package com.peopledelete;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.peopledelete.mapper.OrigindayrecordsMapper;
import com.peopledelete.pojo.Origindayrecords;
import com.peopledelete.service.OrigindayrecordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * @author cyt
 * @create 2020-04-26 18:54
 */
@Component
public class Test {

    @Autowired
    OrigindayrecordsMapper mapper;


    public ArrayList<HashMap> context() {
        // 先查出来当天的记录数
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String dateString = formatter.format(currentTime);
        QueryWrapper<Origindayrecords> wrapper = new QueryWrapper<>();
        wrapper.eq("date", dateString);
        System.out.println(dateString);
        List<Origindayrecords> list = mapper.selectList(wrapper);


        System.out.println("size: " + list.size());
        // 在按照小时来查询
        ArrayList<HashMap> arrayList = new ArrayList<>();
        HashMap<Integer, Origindayrecords> map;
        for (int i = 0; i <= 24; i++) {
            map = new HashMap<>();
            for (Origindayrecords records : list) {
                if (records.getHour().equals(i)) {
                    map.put(i, records);
                    arrayList.add(map);
                }
            }
        }
        arrayList.forEach(System.out::println);


        return arrayList;
    }

}